package com.mk.interceptor.wbheader;

import act.app.ActionContext;
import com.mk.domain.ZMembers;
import com.mk.util.Redis;
import org.osgl.inject.ValueLoader;
import org.osgl.util.S;

@SuppressWarnings("unused")
public class WbHeaderLoginUserFinder extends ValueLoader.Base {
    @Override
    public Object get() {
        ActionContext context = ActionContext.current();
        if (context != null) {
            ZMembers members = context.attribute("members");
            if (members == null) {
                String devid = context.req().header("devid");
                if (S.isBlank(devid)) {
                    devid = context.req().paramVal("devid");
                }
                if (S.isNotBlank(devid)) {
                    try {
                        members = Redis.userDb.getBucket(devid, ZMembers.class).get();
                        context.attribute("members", members);
                    } catch (Exception e) {
                        Redis.userDb.getBucket(devid, ZMembers.class).deleteAsync();
                        e.printStackTrace();
                    }
                }
            }
            return members;
        }
        return null;
    }

}
